
$(function(){
//	setData();
	init();
});

var dataBase = null;

function init() {
	var jsonParam = {};
	jsonParam.appId = getArgsFromHref('appId');
	jsonParam.orderId = getArgsFromHref('orderId');
	jsonParam.sign = getArgsFromHref('sign');
		
	padMarketing.ajaxNormal("/pad_marketing/main/appGetSuccess.action",jsonParam,
		function (data){
			dataBase = data;
			console.log(dataBase)
			var appBase = dataBase.appBase;
			$("#productName").html(appBase.productName);
			$("#preprintedNo").html(appBase.preprintedNo);
			$("#policyRef").html(appBase.policyRef);
			$("#nbPremium").html(formatMoney(appBase.nbPremium));
			var sucFlag = getArgsFromHref('sucFlag');
			if('1'==sucFlag){
				$("#txt").text("恭喜您投保成功!");
				$("#txt1").html("投保");
			}
		},
		function(data){
			
		}
	);
}

function setData() {
	var insured = getArgsFromHref('preprintedNo');
	var policyRefs = getArgsFromHref('policyRef');
	$.ajax({
		type : "post",
		url : "/pad_marketing/main/shadowupload.action",
		dataType : "json",
		data : {
		   	'preprintedNo':insured,
			'policyRef':policyRefs
		},
		success : function(data) {
			console.log(data);
		},
		error : function(data) {
				
		}
	});
}

function finishCheck() {
	var pendingAppBases = dataBase.pendingAppBases;
	if(!pendingAppBases || pendingAppBases.length < 1) {
		window.location.href = "/pad_marketing/ordermanager/index.action";
	} else {
		$('#change').remove();
		var p = '<div class="open-body font-16"  id="change"  ><p  class="add font-12 gray">请点选其中的一张订单继续投保操作，剩余订单请在订单书架中查找</p></div>';
		$('#open6 h4').after(p);
		for (var i = 0; i < pendingAppBases.length; i++) {

			var add_risk = '<div class="show"><div class="blank-1"></div><div class="form-group"><div class="col-md-4"><p class="p-overflow" title="">'
					+ pendingAppBases[i].productName
					+ '</p></div><div class="col-md-6 text-right"><p class="p-overflow">订单号：<span class="orange">'
					+ pendingAppBases[i].orderId
					+ '</span></p> </div><div class="col-md-2 text-right"><div  class="radio_blo"><input id="input'
					+ i
					+ '" data="'
					+ pendingAppBases[i]
					+ '" type="radio" name="xx" /><label for="input'
					+ i
					+ '">&nbsp;</label></div></div></div><hr></div>';
			$('.add').append(add_risk);
		}

		$(".radio_blo input").click(function() {
			sessionStorage.removeItem('appBase');
			var ind = $("input[name=xx]:checked").closest('.show').index();
//			console.log(pendingAppBases[ind]);
			if(ind!=-1){
				$('#text-center').off().on('click',function(){
					sessionStorage.appBase = JSON.stringify(pendingAppBases[ind]);
					if(pendingAppBases[ind].status == "I") {
						padMarketing.ajaxNormal(
								"/pad_marketing/main/appopen.action",
								pendingAppBases[ind],
								function (data){
									sessionStorage.setItem("returnUrl", "/pad_marketing/ordermanager/index.action");
				   				 	window.location.href="/pad_marketing/purchaseNote/index.action";						
								},
								function(data){}
						);
					} else if(pendingAppBases[ind].status == "S") {
						window.location.href="/pad_marketing/main/sign.action?url=ordermanager/index.action";
					} else if(pendingAppBases[ind].status == "U") {
						window.location.href="/pad_marketing/main/cardPhoto.action?url=/pad_marketing/ordermanager/date.action";
					} else if(pendingAppBases[ind].status == "P") {
						window.location.href="/pad_marketing/main/editPay.action";
					}
				});
			}
			
		});
		showDiv('open6');
	}
}

function goToReceipt(){
	var contractId = sendData.CONTRACT_ID;
	var policyRef  = sendData.POLICY_REF;
	window.location.href="/pad_marketing/note/eReceipt.action?contractId="+contractId+"&policyRef="+policyRef;
}

